package com.example.demo.controller;

import com.example.demo.dao.Company;
import com.example.demo.service.impl.CompanyServiceImpl;
import com.example.demo.service.impl.ExecutiveServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/recycle")
public class RecycleController {
    @Autowired
    private CompanyServiceImpl companyService;

    @Autowired
    private ExecutiveServiceImpl executiveService;

    /**
     * 撤销
     * @param code
     * @return
     */
    @PostMapping("/retract/{code}")
    public String retractCompanyInfoByCCode (@PathVariable String code) {

        Company company = companyService.selectCompanyInfoByCCode(code);
        company.setIsDel(0);
        Boolean deleteJudge = companyService.updateCompanyInfo(company);

        if (deleteJudge) {
            return "success";
        } else {
            return "error";
        }
    }

    /**
     * 删除
     */
    @PostMapping ("/delete/{code}")
    @Transactional
    public String deleteCompanyInfoByCCode(@PathVariable String code) {

        Integer deleteJudge = companyService.deleteCompanyInfoByCCode(code);

        if (deleteJudge != 0) {
            return "success";
        } else {
            return "error";
        }

    }

    /**
     * 根据isDel查询企业信息列表
     * @return
     */
    @RequestMapping("/select")
    public List<Company> selectRecycleCompany(){

        return companyService.findCompanyByIsDel(1);

    }
}
